package com.gitee.flyzing.jxt.component;

import com.gitee.flyzing.jxt.CommonUtil;
import org.apache.poi.ss.usermodel.Cell;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JXTEachCell extends JXTCell {
    private String itemName;
    private List items;

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public List getItems() {
        return items;
    }

    public void setItems(List items) {
        this.items = items;
    }

    @Override
    public void parseCell(Cell cell, Object datas) {
        String cellValue = cell.getStringCellValue();
        String exp = "\\{\\{\\s*jxt.each\\s*(\\w*)\\s*in\\s*(\\w*)\\s*\\}\\}";
        Pattern p = Pattern.compile(exp);
        Matcher m = p.matcher(cellValue);
        if (m.find()) {
            String itemName = m.group(1);
            String listName = m.group(2);
            List items = (List) CommonUtil.getPropertyValue(datas, listName);
            this.items = items;
            this.itemName = itemName;
        }
    }
}
